<!-- 个人中心 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-gradual-pink" :isBack="true"><block slot="content">趣豆账单</block></cu-custom>
		<view class="item-list">
			<view v-for="(item, index) in dataList" :key="index" class="item-box weui-cell">
				<view class="item-time">{{item.createTime}}</view>
				<view class="item-right">
					<view class="remark">{{item.remark}}</view>
					<view class="jia" v-if="item.coinType == '0'">+{{item.coinNum}}</view>
					<view class="jian" v-else>-{{item.coinNum}}</view>
				</view>
			</view>
		</view>
		<view class="loadmore-box" v-if="dataList.length > 0">
			<u-loadmore :status="status" @loadmore="load"></u-loadmore>
		</view>
		<u-back-top :scrollTop="scrollTop"></u-back-top>
		<user-auth></user-auth>
	</view>
</template>

<script>
	import {mapState} from 'vuex';
	export default {
		data() {
			return {
				status: 'loadmore',
				isEnd: false,
				current: 1,
				pageSize: 20,
				scrollTop: 0,
				dataList: []
			}
		},
		onLoad() {
			this.query();
		},
		onReachBottom() {
			this.loadmore();
		},
		computed: {
			...mapState(['chat_flag']),
		},
		methods: {
			query() {
				this.current = 1;
				this.isEnd = false;
				this.status = 'loadmore';
				this.loadquery();
			},
			async loadquery() {
				var res = await this.getDataList();
				this.dataList = res.rows;
			},
			load() {
				this.loadmore();
			},
			async loadmore() {
				this.status = 'loading';
				if(this.isEnd){
					this.status = 'nomore';
					return;
				}
				var res = await this.getDataList();
				this.dataList = this.dataList.concat(res.rows);
			},
			async getDataList() {
				var res = await this.$u.get('/pay/userCoin/getMyList', {
					pageNum: this.current,
					pageSize: this.pageSize,
				});
				var totalPage = Math.ceil(res.total/this.pageSize);
				this.pages = totalPage;
				this.current ++;
				this.status = 'loadmore';
				if(this.current > this.pages){
					this.status = 'nomore';
					this.isEnd = true;
				}
				return res;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.item-list {
		padding: 0 15px;
	}
	.item-box {
		display: flex;
		align-items: center;
		position: relative;
		padding: 15px 0;
	}
	.item-right {
		margin-left: 15px;
		display: flex;
		flex: 1;
		align-items: center;
		justify-content: space-between;
	}
	.item-time {
		color: #b5a5a5;
		font-size: 28rpx;
	}
	.jia {
		color: #f17373;
		font-size: 28rpx;
		font-weight: bold;
	}
	.jian {
		color: #d45959;
		font-size: 28rpx;
		font-weight: bold;
	}
	.remark {
		color: #4e4848;
		font-size: 28rpx;
		font-weight: bold;
	}
	
	.weui-cell:after {
	    content: " ";
	    position: absolute;
	    left: 0;
	    bottom: 0;
	    right: 0;
	    height: 1px;
	    border-bottom: 1px solid #e5e5e5;
	    color: #e5e5e5;
	    -webkit-transform-origin: 0 0;
	    transform-origin: 0 0;
	    -webkit-transform: scaleY(0.5);
	    transform: scaleY(0.5);
	    z-index: 2;//看情况使用
	}
	.loadmore-box {
		padding: 15px;
	}
</style>
